#include <Arduino.h>
#include <WiFi.h>
#include <WString.h>
#include "cserver.h"
#include <http_parser.h>

String APSSID("yunni");
String APPASS("12345678");
//本地IP
String LOCALIP("192.168.137.1");
//网关
String GATEWAY("192.168.137.1");
//子网掩码
String SUBNET("255.255.255.0");

IPAddress localIp;
IPAddress gateway;
IPAddress subnet;

CServer * server;

void setup() {
  //初始化WiFi
  localIp.fromString(LOCALIP);
  gateway.fromString(GATEWAY);
  subnet.fromString(SUBNET);
  WiFi.softAPConfig(localIp, gateway, subnet);
  //开启WIFI并设置名字和密码
  WiFi.softAP(APSSID.c_str(), APPASS.c_str());
  Serial.begin(115200);
  Serial.println("initial success!");

  server = new CServer(LOCALIP.c_str(), 80, 128, 1024, 1024);
  if(server->socket() > 0){
    Serial.printf("server listen success %s:%d\n", LOCALIP.c_str(), 80);
  }else{
    Serial.printf("server listen fail %s:%d\n", LOCALIP.c_str(), 80);
  }
}

void loop() {
  server->main();
}
